<%@page import="com.hicampus.portlet.verifycontact.MaxMindUtil"%>

<%@ include file="/html/common/init.jsp" %>

<%
String ipAddress = PortalUtil.getOriginalServletRequest(request).getRemoteAddr();

if (!Validator.isIPAddress(ipAddress)) {
// give a dummy value
ipAddress = "122.167.129.104";
}

GeoLocation location = (GeoLocation)portletSession.getAttribute("LIFERAY_SHARED_CURRENT_LOCATION", PortletSession.APPLICATION_SCOPE);

if (location == null) {
location = MaxMindUtil.getLocation(ipAddress);
portletSession.setAttribute("LIFERAY_SHARED_CURRENT_LOCATION", location, PortletSession.APPLICATION_SCOPE);
}
%>

<style type="text/css">
#map_canvas {
min-width: 100%;
min-height: 200px;
}
</style>

<script type="text/javascript">
var <portlet:namespace />map;
var <portlet:namespace />initialLocation;

var lattitude = '<%= location.getLatitude() %>';
var longitude = '<%= location.getLongitude() %>';

function <portlet:namespace />initialize() {
	var myLatlng = new google.maps.LatLng(lattitude, longitude);
	var myOptions = {
		zoom : 5,
		center : myLatlng,
		disableDefaultUI: true,
		mapTypeId : google.maps.MapTypeId.ROADMAP
	};
	<portlet:namespace />map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
		var marker = new google.maps.Marker({
		map : <portlet:namespace />map,
		position : myLatlng,
		title:"You are here"
		});
}

function <portlet:namespace />loadScript() {
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=<portlet:namespace />initialize";
	document.body.appendChild(script);
}

window.onload = <portlet:namespace />loadScript;
</script>
<div id="map_canvas"></div>